package com.douchuang.archetype.controller;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/statistic")
public class StatisticController {

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello() {
        // save it to db
        return "hello";
    }

    @RequestMapping(value = "/pageScore", method = RequestMethod.POST)
    public Object score(@RequestBody PageScore pageScore) {
        // save it to db

        return  null;
    }

    @RequestMapping(value = "/pageViewTime", method = RequestMethod.POST)
    public Resp score(@RequestBody PageViewTime pageViewTime) {
        // save it to db
        System.out.println(pageViewTime);
        System.out.println(pageViewTime.getPageUrl());
        Resp resp = new Resp();
        resp.setCode("ok");
        return  resp;
    }

    @Data
    static class PageBase {
        private String pageUrl;
        private String pageTitle;
        private String user;
    }


    @Data
    @EqualsAndHashCode(callSuper=true)
    static class PageScore extends PageBase {
        Integer score;
    }

    @Data
    @EqualsAndHashCode(callSuper=true)
    static class PageViewTime extends PageBase {
        Integer viewTime; // seconds
    }

    @Data
    static class Resp {
        String code;
    }

}
